package com.nowcoder.code.hjnc;

import java.util.HashMap;
import java.util.LinkedList;

public class NC41 {

    public static void main(String[] args) {
        HashMap<Integer, Integer> map = new HashMap<>();
        map.put(0, 1);
        System.out.println(map.put(0, 2));
    }

    public int maxLength(int[] arr) {

        HashMap<Integer, Integer> map = new HashMap<>();
        int max = 0;
        int result = 0;
        int start = 0;
        for (int i = 0; i < arr.length; i++) {
            if (map.containsKey(arr[i])) {
                while (arr[i] != arr[start]) {
                    map.remove(arr[start]);
                    start++;
                }
                start++;
                result = i - start + 1;
            } else {
                result++;
                max = Math.max(max, result);
                map.put(arr[i], i);
            }
        }
        return max;

    }
}
